interface IuiToggleClassScope extends ng.IScope {
  uiToggleClass:any;
  target:any;
}
class uiToggleClass implements ng.IDirective{
    constructor(){}
    static instance():ng.IDirective{return new uiToggleClass}
    restrict:string='AC';
    link($scope:IuiToggleClassScope,elements:ng.IAugmentedJQuery,attrs:ng.IAttributes){
         elements.on('click', function (e) {
                      e.preventDefault();
                      var classes = attrs['uiToggleClass'].split(','),
                          targets = (attrs['target'] && attrs['target'].split(',')) || Array(elements),
                          key = 0;
                      angular.forEach(classes, function (_class) {
                          var target = targets[(targets.length && key)];
                          (_class.indexOf('*') !== -1) && magic(_class, target);
                          $(target).toggleClass(_class);
                          key++;
                      });
                      $(elements).toggleClass('active');

                      function magic(_class, target) {
                          var patt = new RegExp('\\s' +
                              _class.
                                replace(/\*/g, '[A-Za-z0-9-_]+').
                                split(' ').
                                join('\\s|\\s') +
                              '\\s', 'g');
                          var cn = ' ' + $(target)[0].className + ' ';
                          while (patt.test(cn)) {
                              cn = cn.replace(patt, ' ');
                          }
                          $(target)[0].className = $.trim(cn);
                      }
                  });

    }
}
angular.module('tms').directive('uiToggleClass', uiToggleClass.instance);